<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>添加题库</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/laypage.css">
    <script src="js/jquery/jquery.min.js"></script>
    <script src="js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script src="js/jquery.validation/1.14.0/messages_zh.min.js"></script>
    <style>
        input.error {
            border: 1px solid #FF0000;
        }
    </style>
</head>
<body>
<div class="container">
    <form id="addLibForm">
        <br/>
        <div class="form-group">
            <label for="lib_name">题库名称：</label>
            <input type="text" class="form-control" id="lib_name" name="lib_name" placeholder="题库名称">
        </div>
        <div class="form-group">
            <label for="desc">题库描述：</label>
            <input type="text" class="form-control" id="desc" name="desc" placeholder="题库描述">
        </div>

        <div class="form-group">
            <button type="button" id="saveBtn" class="btn btn-success">提交</button>
            <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
        </div>
    </form>
</div>
<script>
    var addLib = function () {
        if(!check().form()){
            return
        }
        $.ajax({
            type:'GET',
            dataType:'json',
            url:'/lib/addLib.do',
            data:{
                "lib_name":$("#lib_name").val(),
                "lib_desc":$("#desc").val(),
            },
            success:function () {
                $("#cancelBtn").click();
            }
        });
    }
    $("#saveBtn").click(function () {
        addLib();
    });
    $("#cancelBtn").click(function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.getLibList();
        parent.layer.close(index);
    });
    //校验操作
    function check() {
        return $('#addLibForm').validate({
            rules:{
                lib_name:{
                    required:true
                },
                desc:{
                    required:true
                },
            },
            messages:{
                lib_name:{
                    required:""
                },
                desc:{
                    required:""
                },
            }
        });
    }
</script>
</body>
</html>